package cc.rengu.igas.channel.upgw.core.service.trans;

import cc.rengu.igas.channel.upgw.core.service.base.UpgwBaseService;
import cc.rengu.igas.channel.upgw.common.constant.UpgwHeaderConstant;
import cc.rengu.igas.channel.upgw.common.constant.UpgwParamConstant;
import cc.rengu.igas.channel.upgw.common.constant.UpgwTreeNodeConstant;
import cc.rengu.igas.channel.upgw.common.enums.UpgwRespCodeEnum;
import cc.rengu.igas.channel.upgw.facade.bean.EncryptAssInfo;
import cc.rengu.igas.channel.upgw.facade.bean.UpgwMchntInfo;
import cc.rengu.igas.channel.upgw.facade.bean.TermInfo;
import cc.rengu.igas.channel.upgw.facade.request.UpgwEnterpriseGatewayPaymentRequest;
import cc.rengu.igas.channel.upgw.facade.response.UpgwEnterpriseGatewayPaymentResponse;
import cc.rengu.jradp.schedule.ScheduleImpl;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.utility.util.AmountUtil;
import cc.rengu.oltp.utility.util.ConvertUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.base.StringUtil;

/**
 * @author wukefan
 * @version 1.0.0
 * @date 2020/10/6 14:16
 */
public class UpgwEnterpriseGatewayPaymentService extends UpgwBaseService {

    @Override
    protected Object beforeBizProcess() throws Exception {
        UpgwEnterpriseGatewayPaymentRequest request = new UpgwEnterpriseGatewayPaymentRequest();
        ConvertUtil.convertOutput(request);
        return request;
    }

    @Override
    protected BizResponse callBizService(Object request) throws Exception {

        XmlTreeUtil xmlTree = new XmlTreeUtil();
        UpgwEnterpriseGatewayPaymentRequest upgwEnterpriseGatewayPaymentRequest = (UpgwEnterpriseGatewayPaymentRequest) request;
        BizResponse<UpgwEnterpriseGatewayPaymentResponse> bizResponse = new BizResponse<>();
        UpgwEnterpriseGatewayPaymentResponse response = new UpgwEnterpriseGatewayPaymentResponse();
        if (!verifyRequest(upgwEnterpriseGatewayPaymentRequest)) {
            response.setRespCode(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL.getRespCode());
            response.setRespDesc(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL.getRespDesc());
            bizResponse.setResult(response);
            return bizResponse;
        }

        /* 将请求赋值到xml中 */
        requestToXMLTree(xmlTree, upgwEnterpriseGatewayPaymentRequest);

        /* TODO 演示环境默认返回成功 START */
        if (AppParamConstant.DEFAULT_ENV.equals(AppParamConstant.APPLICATION_ENV)) {
            //成功 转换成功应答码为统一应答码，调用方根据返回00000000判断业务是否成功
            rglog.info("演示环境默认返回成功");
            response.setRespCode(UpgwRespCodeEnum.ACCEPT_SUCCESS.getRespCode());
            response.setRespDesc(UpgwRespCodeEnum.ACCEPT_SUCCESS.getRespDesc());
            bizResponse.setResult(response);
            return bizResponse;
        }
        /* TODO 演示环境默认返回成功 END */

        try {
            int retCode = schedule.callService(UpgwParamConstant.UPGW_COMMUNICATION_SVC_NM, UpgwParamConstant.UPGW_COMMUNICATION_SVC_LABEL);
            /*判断retCode返回值*/
            /*通讯成功*/
            if (ScheduleImpl.SERVICE_SUCCESS == retCode) {
                /*判断状态码*/
                String status = xmlTree.getXmlTreeStringValue(UpgwHeaderConstant.STATUS);
                if (UpgwParamConstant.STATUS_SUCC.equals(status)) {
                    rglog.debug("调用通道业务成功");
                    //通道调用成功的应答处理
                    //成功 转换成功应答码为统一应答码，调用方根据返回00000000判断业务是否成功
                    response.setRespCode(UpgwRespCodeEnum.ACCEPT_SUCCESS.getRespCode());
                    response.setRespDesc(UpgwRespCodeEnum.ACCEPT_SUCCESS.getRespDesc());
                    EncryptAssInfo encryptAssInfo = new EncryptAssInfo();
                    encryptAssInfo.setEncyAlgoType(xmlTree.getXmlTreeStringValue(UpgwTreeNodeConstant.ENCRPASSINF_ENCRPENCALGO));
                    encryptAssInfo.setEncyCertSn(xmlTree.getXmlTreeStringValue(UpgwTreeNodeConstant.ENCRPASSINF_ENCRPENCSN));
                    encryptAssInfo.setEncyKey(xmlTree.getXmlTreeStringValue(UpgwTreeNodeConstant.ENCRPASSINF_ENCRPENCKEY));
                    encryptAssInfo.setEncyMsg(xmlTree.getXmlTreeStringValue(UpgwTreeNodeConstant.ENCRPMSSG));
                    encryptAssInfo.setMdAlgoType(xmlTree.getXmlTreeStringValue(UpgwTreeNodeConstant.ENCRPASSINF_ENCRPMDALGO));
                    encryptAssInfo.setSignCertSn(xmlTree.getXmlTreeStringValue(UpgwTreeNodeConstant.ENCRPASSINF_ENCRPSIGNSN));
                    encryptAssInfo.setSignEncyAlgo(xmlTree.getXmlTreeStringValue(UpgwTreeNodeConstant.ENCRPASSINF_ENCRPSIGNENCALGO));
                    response.setEncryptAssInfo(encryptAssInfo);
                    response.setChannelSeqNum(xmlTree.getXmlTreeStringValue(UpgwTreeNodeConstant.TRXINF_TRXID));
                    response.setPayerIssrChannelId(xmlTree.getXmlTreeStringValue(UpgwTreeNodeConstant.PYERINF_ISSRCHNNLID_RSP));
                    response.setPayerIssrChannelUrl(xmlTree.getXmlTreeStringValue(UpgwTreeNodeConstant.PYERINF_ISSRCHNNLURL));
                    bizResponse.setResult(response);
                } else if (UpgwParamConstant.STATUS_FAIL.equals(status)) {
                    rglog.debug("调用通道业务失败");
                    //通过判断应答码，判定交易状态是否为超时;ESB超时错误码为E000A703
                    String code = xmlTree.getXmlTreeStringValue(UpgwHeaderConstant.CODE);
                    if (StringUtil.isNullorEmpty(code)) {
                        response.setRespCode(UpgwParamConstant.DEFAULT_ERR_CODE);
                    } else if (UpgwParamConstant.ESB_TIME_OUT_E000A703.equals(code)) {
                        response.setRespCode(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode());
                    } else {
                        response.setRespCode(code);
                    }
                    String desc = xmlTree.getXmlTreeStringValue(UpgwHeaderConstant.DESC);
                    if (StringUtil.isNullorEmpty(desc)) {
                        response.setRespDesc(UpgwParamConstant.DEFAULT_ERR_DESC);
                    } else {
                        response.setRespDesc(desc);
                    }
                    bizResponse.setResult(response);
                } else {
                    rglog.debug("调用通道业务未知");
                    String code = xmlTree.getXmlTreeStringValue(UpgwHeaderConstant.CODE);
                    if (StringUtil.isNullorEmpty(code)) {
                        response.setRespCode(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode());
                    } else {
                        response.setRespCode(code);
                    }
                    String desc = xmlTree.getXmlTreeStringValue(UpgwHeaderConstant.DESC);
                    if (StringUtil.isNullorEmpty(desc)) {
                        response.setRespDesc(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode());
                    } else {
                        response.setRespDesc(desc);
                    }
                    bizResponse.setResult(response);
                }
            } else if (ScheduleImpl.SERVICE_TIMEOUT == retCode) {
                //调用超时 赋值应答
                rglog.error("callService {} 失败！返回值={}", UpgwParamConstant.UPGW_COMMUNICATION_SVC_NM, retCode);
                response.setRespCode(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode());
                response.setRespDesc(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespDesc());
                bizResponse.setResult(response);
                return bizResponse;
            } else {
                //调用明确失败
                rglog.error("callService {} 失败！返回值={}", UpgwParamConstant.UPGW_COMMUNICATION_SVC_NM, retCode);
                response.setRespCode(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR.getRespCode());
                response.setRespDesc(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR.getRespDesc());
                bizResponse.setResult(response);
                return bizResponse;
            }
        } catch (Exception e) {
            //失败赋值应答码为明确失败及应答消息直接退出
            rglog.error("{}", StringUtil.ExceptionToString(e));
            response.setRespCode(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR.getRespCode());
            response.setRespDesc(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR.getRespDesc());
            bizResponse.setResult(response);
            return bizResponse;
        }
        bizResponse.setResult(response);
        return bizResponse;
    }

    private void requestToXMLTree(XmlTreeUtil xmlTree, UpgwEnterpriseGatewayPaymentRequest upgwEnterpriseGatewayPaymentRequest) throws Exception {
        /*公共报文信息*/
        /*请求方机构代码*/
        xmlTree.setXmlTreeStringValue(UpgwHeaderConstant.BRANCH_ID, upgwEnterpriseGatewayPaymentRequest.getHeader().getInstId() + UpgwParamConstant.DEFAULT_VIRTUAL_INST_ID);
        /*服务渠道代码*/
        xmlTree.setXmlTreeStringValue(UpgwHeaderConstant.CHANNEL_ID, UpgwParamConstant.CHANNEL_ID);
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getHeader().getFrontChannelId())) {
            xmlTree.setXmlTreeStringValue(UpgwHeaderConstant.CHANNEL_ID, upgwEnterpriseGatewayPaymentRequest.getHeader().getFrontChannelId());
        }
        /*请求方系统代码*/
        xmlTree.setXmlTreeStringValue(UpgwHeaderConstant.REQUESTER_ID, UpgwParamConstant.REQUEST_ID);
        /*ESB服务码*/
        xmlTree.setXmlTreeStringValue(UpgwHeaderConstant.SERVICE_ID, upgwEnterpriseGatewayPaymentRequest.getHeader().getTxnNum());
        /*请求方服务流水号*/
        xmlTree.setXmlTreeStringValue(UpgwHeaderConstant.SERVICE_SN, upgwEnterpriseGatewayPaymentRequest.getHeader().getTraceNo());
        /*请求方服务时间*/
        xmlTree.setXmlTreeStringValue(UpgwHeaderConstant.SERVICE_TIME, upgwEnterpriseGatewayPaymentRequest.getHeader().getTransDate() + upgwEnterpriseGatewayPaymentRequest.getHeader().getTransTime());
        /*版本号*/
        xmlTree.setXmlTreeStringValue(UpgwHeaderConstant.VERSION_ID, UpgwParamConstant.VERSION_ID);

        /*业务种类*/
        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.BIZTP, upgwEnterpriseGatewayPaymentRequest.getBusiType());
        /*业务功能*/
        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.BIZFUNC, UpgwParamConstant.BIZ_FUNC_UPGW_FULL_PAYMENT);
        /*初始交易类型*/
        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.INITRXTP, UpgwParamConstant.INITRXTP_ENTERPRISE);
        /*交易金额*/
        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.TRXAMT, AmountUtil.changeY2F(upgwEnterpriseGatewayPaymentRequest.getOrderAmt()));
        /*业务辅助信息*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getBusiReserveInfo())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.BIZASSINF_BIZASSINFRSV, upgwEnterpriseGatewayPaymentRequest.getBusiReserveInfo());
        }
        /*发起方保留域*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getAcqrReserved())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.TRXINF_ACQRRESERVED, upgwEnterpriseGatewayPaymentRequest.getAcqrReserved());
        }
        /*交易终端类型*/
        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.TRXTRMINF_TRXTRMTP, upgwEnterpriseGatewayPaymentRequest.getTermInfo().getTermType());
        /*交易终端编码*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getTermInfo().getTermNo())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.TRXTRMINF_TRXTRMNO, upgwEnterpriseGatewayPaymentRequest.getTermInfo().getTermNo());
        }
        /*IP地址*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getTermInfo().getIpAddr())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.TRXTRMINF_SOURCEIP, upgwEnterpriseGatewayPaymentRequest.getTermInfo().getIpAddr());
        }
        /*MAC地址*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getTermInfo().getMacAddr())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.TRXTRMINF_MAC, upgwEnterpriseGatewayPaymentRequest.getTermInfo().getMacAddr());
        }
        /*设备号*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getTermInfo().getDevId())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.TRXTRMINF_DEVID, upgwEnterpriseGatewayPaymentRequest.getTermInfo().getDevId());
        }
        /*网关渠道标识*/
        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.PYERINF_ISSRCHNNLID, upgwEnterpriseGatewayPaymentRequest.getPayerIssrChannelId());
        /*报文初始发起机构标识*/
        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.ORIISSRID, upgwEnterpriseGatewayPaymentRequest.getOriIssrId());
        /*收款方账户*/
        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.PYEEINF_PYEEACCTID, upgwEnterpriseGatewayPaymentRequest.getPayeeAcctInfo());
        /*收款方名称*/
        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.PYEEINF_PYEENM, upgwEnterpriseGatewayPaymentRequest.getPayeeAcctName());
        /*收款方开户行支付系统行号*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getPayeeOpenBankNo())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.PYEEINF_PYEEBNKNO, upgwEnterpriseGatewayPaymentRequest.getPayeeOpenBankNo());
        }
        /*收款方开户行支付系统行名称*/
        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.PYEEINF_PYEEBNKNM, upgwEnterpriseGatewayPaymentRequest.getPayeeOpenBankName());
        /*回调地址*/
        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.PYEEINF_ACQRCHNNLURL, upgwEnterpriseGatewayPaymentRequest.getPayeeBackUrl());
        /*产品类型*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getProductType())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.PRODUCTINF_PRODUCTTP, upgwEnterpriseGatewayPaymentRequest.getProductType());
        }
        /*产品辅助信息*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getProductAssInfo())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.PRODUCTINF_PRODUCTASSINFORMATION, upgwEnterpriseGatewayPaymentRequest.getProductAssInfo());
        }
        /*订单号*/
        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.ORDRINF_ORDRID, upgwEnterpriseGatewayPaymentRequest.getOrderId());
        /*订单详情*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getOrderDesc())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.ORDRINF_ORDRDESC, upgwEnterpriseGatewayPaymentRequest.getOrderDesc());
        }
        /*商户编码*/

        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.MRCHNTINF_MRCHNTNO, upgwEnterpriseGatewayPaymentRequest.getMchntInfo().getMchntNo());
        /*商户类别*/
        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.MRCHNTINF_MRCHNTTPID, upgwEnterpriseGatewayPaymentRequest.getMchntInfo().getMchntType());
        /*商户名称*/
        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.MRCHNTINF_MRCHNTPLTFRMNM, upgwEnterpriseGatewayPaymentRequest.getMchntInfo().getMchntName());
        /*交易受理渠道*/
        xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.MRCHNTINF_TRXCHANNLTP, upgwEnterpriseGatewayPaymentRequest.getMchntInfo().getMchntTransSource());
        /*二级商户编码*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getMchntInfo().getSubMchntNo())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.SUBMRCHNTINF_SUBMRCHNTNO, upgwEnterpriseGatewayPaymentRequest.getMchntInfo().getSubMchntNo());
        }
        /*二级商户所属的商户类别代码*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getMchntInfo().getSubMchntType())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.SUBMRCHNTINF_SUBMRCHNTTPID, upgwEnterpriseGatewayPaymentRequest.getMchntInfo().getSubMchntType());
        }
        /*用于标识二级商户的名称*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getMchntInfo().getSubMchntName())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.SUBMRCHNTINF_SUBMRCHNTPLTFRMNM, upgwEnterpriseGatewayPaymentRequest.getMchntInfo().getSubMchntName());
        }
        /*设备型号*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getDeviceMode())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.RSKINF_DEVICEMODE, upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getDeviceMode());
        }
        /*设备语言*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getDeviceLanguage())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.RSKINF_DEVICELANGUAGE, upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getDeviceLanguage());
        }
        /*GPS 位置*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getDeviceLocation())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.RSKINF_EXTENSIVEDEVICELOCATION, upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getDeviceLocation());
        }
        /*SIM 卡号码*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getDeviceNo())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.RSKINF_DEVICENUMBER, upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getDeviceNo());
        }
        /*SIM 卡数量*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getDeviceSimNum())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.RSKINF_DEVICESIMNUMBER, upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getDeviceSimNum());
        }
        /*账户 ID*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getAccountId())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.RSKINF_ACCOUNTIDHASH, upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getAccountId());
        }
        /*风险评分*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getRiskScore())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.RSKINF_RISKSCORE, upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getRiskScore());
        }
        /*原因码*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getRiskReasonCode())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.RSKINF_RISKREASONCODE, upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getRiskReasonCode());
        }
        /*收单端用户注册日期*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getMchntUsrRgstrTm())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.RSKINF_MCHNTUSRRGSTRTM, upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getMchntUsrRgstrTm());
        }
        /*收单端注册账户邮箱地址*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getMchntUsrRgstrEmail())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.RSKINF_MCHNTUSRRGSTREMAIL, upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getMchntUsrRgstrEmail());
        }
        /*收货省*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getRcvProvince())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.RSKINF_RCVPROVINCE, upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getRcvProvince());
        }
        /*收货市*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getRcvCity())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.RSKINF_RCVCITY, upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getRcvCity());
        }
        /*商品类型*/
        if (!StringUtil.isNullorEmpty(upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getGoodsClass())) {
            xmlTree.setXmlTreeStringValue(UpgwTreeNodeConstant.RSKINF_GOODSCLASS, upgwEnterpriseGatewayPaymentRequest.getRiskInfo().getGoodsClass());
        }
    }

    private boolean verifyRequest(UpgwEnterpriseGatewayPaymentRequest upgwEnterpriseGatewayPaymentRequest) {
        UpgwMchntInfo mchntInfo = upgwEnterpriseGatewayPaymentRequest.getMchntInfo();
        if (null == mchntInfo) {
            rglog.error("mchntInfo信息为null！");
            return false;
        }
        TermInfo termInfo = upgwEnterpriseGatewayPaymentRequest.getTermInfo();
        if (null == termInfo) {
            rglog.error("termInfo信息为null！");
            return false;
        }
        String acctNo = upgwEnterpriseGatewayPaymentRequest.getBusiType();
        String certNum = upgwEnterpriseGatewayPaymentRequest.getOrderAmt();
        String certType = upgwEnterpriseGatewayPaymentRequest.getTermInfo().getTermType();
        String custName = upgwEnterpriseGatewayPaymentRequest.getPayerIssrChannelId();
        String oriIssrId = upgwEnterpriseGatewayPaymentRequest.getOriIssrId();
        String payeeAcctInfo = upgwEnterpriseGatewayPaymentRequest.getPayeeAcctInfo();
        String payeeAcctName = upgwEnterpriseGatewayPaymentRequest.getPayeeAcctName();
        String payeeOpenBankName = upgwEnterpriseGatewayPaymentRequest.getPayeeOpenBankName();
        String payeeBackUrl = upgwEnterpriseGatewayPaymentRequest.getPayeeBackUrl();
        String orderId = upgwEnterpriseGatewayPaymentRequest.getOrderId();
        String mchntNo = upgwEnterpriseGatewayPaymentRequest.getMchntInfo().getMchntNo();
        String mchntType = upgwEnterpriseGatewayPaymentRequest.getMchntInfo().getMchntType();
        String mchntName = upgwEnterpriseGatewayPaymentRequest.getMchntInfo().getMchntName();
        String mchntTransSource = upgwEnterpriseGatewayPaymentRequest.getMchntInfo().getMchntTransSource();
        if (StringUtil.isNullorEmpty(acctNo) ||
                StringUtil.isNullorEmpty(certNum) ||
                StringUtil.isNullorEmpty(certType) ||
                StringUtil.isNullorEmpty(oriIssrId) ||
                StringUtil.isNullorEmpty(payeeBackUrl) ||
                StringUtil.isNullorEmpty(orderId) ||
                StringUtil.isNullorEmpty(mchntNo) ||
                StringUtil.isNullorEmpty(mchntType) ||
                StringUtil.isNullorEmpty(mchntName) ||
                StringUtil.isNullorEmpty(mchntTransSource) ||
                StringUtil.isNullorEmpty(payeeAcctInfo) ||
                StringUtil.isNullorEmpty(payeeAcctName) ||
                StringUtil.isNullorEmpty(payeeOpenBankName) ||
                StringUtil.isNullorEmpty(custName)) {
            //失败赋值应答码为明确失败及应答消息直接退出
            rglog.error("缺少一个或多个业务参数！");
            return false;
        }
        rglog.trace("检查请求通过");
        return true;
    }

    @Override
    protected void afterBizProcess(BizResponse response) throws Exception {
        UpgwEnterpriseGatewayPaymentResponse upgwEnterpriseGatewayPaymentResponse = (UpgwEnterpriseGatewayPaymentResponse) response.getResult();
        ConvertUtil.convertInput(upgwEnterpriseGatewayPaymentResponse);
    }
}
